/**
 * 
 */
package com.tw.trips.dao;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.stereotype.Repository;

import com.tw.trips.domain.Activity;
import com.tw.trips.domain.Alert;
import com.tw.trips.domain.Traveller;
import com.tw.trips.domain.Trip;
import com.tw.trips.repository.TravellerRepository;

/**
 * @author M1005264
 * 
 */
@Repository
public class TravellerDAO {

	@Autowired
	Neo4jTemplate template;

	@Autowired
	private TravellerRepository travellerRepository;

	public Traveller getTravellerByEmail(String email) {
		return travellerRepository.findByEmailID(email);
	}

	public Traveller save(Traveller newTraveller) {
		return template.save(newTraveller);
	}

	public Trip updateTrip(Traveller curTraveller, Trip trip) {
		return template.save(trip);
	}

	public Trip saveTrip(Trip trip) {
		return template.save(trip);
	}

	public Set<Trip> getTrips(Traveller curTraveller) {
		return travellerRepository.findByEmailID(curTraveller.getEmailID())
				.getTrips();
	}

	public Traveller addActivity(Trip trip,
			Activity activity) {
		// trip.addActivity(activity);
		// activity.setUpdatedBy(curTraveller);
		return trip.addActivity(template, activity).getCreatedBy();
	}

	public Traveller addAlert(Alert alert) {
		return template.save(alert).getToBeAlerted();
	}
}
